package com.emm.yixun.report.configuration;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.jdbc.DataSourceBuilder;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.PropertySource;
import org.springframework.jdbc.core.JdbcTemplate;

@Configuration
@PropertySource(value={"file:/opt/yixun/emm/db/db.properties"})
public class DataSourceConfig {
	@Bean(name = "reportDataSource")
	@Primary
	@ConfigurationProperties(prefix = "spring.datasource.report")
	public DataSource reportDataSource() {
		return DataSourceBuilder.create().build();
	}
	
	
	@Bean(name = "m2DataSource")
	@ConfigurationProperties(prefix = "spring.datasource.m2")
	public DataSource m2DataSource() {
		return DataSourceBuilder.create().build();
	}
	
	
	@Bean(name = "m2JdbcTemplate")
    public JdbcTemplate m2JdbcTemplate(
            @Qualifier("m2DataSource") DataSource dataSource) {
        return new JdbcTemplate(dataSource);
    }
	
	
}
